package message;

public class Message {
	
	private String command;
	private byte[] originData;	
	private byte[] fileData;	
	private byte[] packet;
	
	// 데이터 사이즈.
	public static final int PACKET_SIZE = 128;
	public static final int COMMAND_SIZE = 10;
	public static final int DATA_SIZE = 4;
	
	// 명령어 종류.
	public static final String LS = "ls";
	public static final String CAT = "cat";
	public static final String SAVE = "save";
	public static final String RM = "rm";
	public static final String MKDIR = "mkdir";
	public static final String RMDIR = "rmdir";
	public static final String CD = "cd";
	public static final String CP = "cp";
	public static final String LOGIN = "login";	 

	
	public Message(String command,  String option) {

		if(null == option)
		
		
		
		switch(command) 
		{
		
		
		}
		
		
	}
	
	private String parsingCommand() {
		
		byte[] bCommand = new byte[COMMAND_SIZE];
		
		System.arraycopy(originData, 0, bCommand, 0, PACKET_SIZE);

		return bCommand.toString();		
	}
	
	private int parsingDataSize() {
		
		byte[] bDataSize = new byte[DATA_SIZE];

		System.arraycopy(originData, 0, bDataSize, COMMAND_SIZE, DATA_SIZE);

		return getInt(bDataSize);
	}
	
	public byte[] getData() {
		
		System.arraycopy(originData, 0, fileData, COMMAND_SIZE + parsingDataSize(), parsingDataSize());
		
		return this.fileData;		
	}
	
	public String getCommand() {
		return this.command;
	}
	
	private int getInt(byte[] bt){
		int temp = 0;
		int[] bt2 = new int[4];
		for(int i=0; i<4; i++)
		{
			bt2[i] = bt[i] < 0 ? ((Byte.MAX_VALUE + 1) * 2) + bt[i] : bt[i];
			temp |= (bt2[i] << (8*(3-i)));
		}
		return temp;
	}
	

}
